﻿Public Class ReportForm

    Private Sub 页面设置ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 页面设置ToolStripMenuItem.Click
        Dim strSql As String = ""
        Dim rs As ADODB.Recordset

        Using frm As New PageSetting

            frm.字体 = 报表字体
            frm.记录条数 = 报表记录条数字

            If frm.ShowDialog(Me) = Windows.Forms.DialogResult.OK Then
                Dim sb As New System.Text.StringBuilder
                Dim bInsert As Boolean = True

                '先查询存在的话更新，不存在的话插入
                strSql = "select * from XSCReportForm where CLASSNAME='" + Me.ClassName + "'"
                rs = ct.GetTable(strSql)
                If rs IsNot Nothing Then
                    If rs.EOF = False Then
                        bInsert = False
                    End If
                    rs.Close()
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(rs)
                    rs = Nothing
                End If

                '表示不存在
                If bInsert Then
                    sb.AppendLine("  insert  ")
                    sb.AppendLine("  into  ")
                    sb.AppendLine("  XSCReportForm  ")
                    sb.AppendLine("  ( CLASSNAME")
                    sb.AppendLine("   ,FontName")
                    sb.AppendLine("   ,GridRowCount")
                    sb.AppendLine("  )  ")
                    sb.AppendLine("  values  ")
                    sb.AppendLine("  (  ? ")
                    sb.AppendLine("    ,? ")
                    sb.AppendLine("    ,? ")
                    sb.AppendLine("  )  ")
                Else '表示存在
                    sb.AppendLine("  Update  ")
                    sb.AppendLine("  XSCReportForm  ")
                    sb.AppendLine("  Set    FontName=? ")
                    sb.AppendLine("        ,GridRowCount=? ")
                    sb.AppendLine("  Where CLASSNAME=? ")
                End If

                Dim cmd As New ADODB.Command
                Dim pa As ADODB.Parameter

                If bInsert Then
                    'CLASSNAME
                    pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adWChar, ADODB.ParameterDirectionEnum.adParamInput, _
                    ClassName.Length, ClassName)
                    cmd.Parameters.Append(pa)

                    'FontName
                    pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adWChar, _
                    ADODB.ParameterDirectionEnum.adParamInput, frm.字体.ToString.Length, frm.字体.ToString)
                    cmd.Parameters.Append(pa)

                    'GridRowCount
                    pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adWChar, _
                    ADODB.ParameterDirectionEnum.adParamInput, frm.记录条数.ToString.Length, frm.记录条数.ToString)
                    cmd.Parameters.Append(pa)
                Else
                    'FontName
                    pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adWChar, _
                    ADODB.ParameterDirectionEnum.adParamInput, frm.字体.ToString.Length, frm.字体.ToString)
                    cmd.Parameters.Append(pa)

                    'GridRowCount
                    pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adWChar, _
                    ADODB.ParameterDirectionEnum.adParamInput, frm.记录条数.ToString.Length, frm.记录条数.ToString)
                    cmd.Parameters.Append(pa)

                    'CLASSNAME
                    pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adWChar, ADODB.ParameterDirectionEnum.adParamInput, _
                    ClassName.Length, ClassName)
                    cmd.Parameters.Append(pa)
                End If

                cmd.CommandText = sb.ToString()
                ct.ExcCommand(cmd)
            End If

            报表字体 = frm.字体
            报表记录条数字 = frm.记录条数
        End Using
    End Sub

    Public Overridable Property 报表字体() As String
        Get
            Return "宋体"
        End Get
        Set(ByVal value As String)

        End Set
    End Property

    Public Overridable Property 报表记录条数字() As Integer
        Get
            Return 50
        End Get
        Set(ByVal value As Integer)

        End Set
    End Property

    Private Sub ReportForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If DesignMode = False Then
            Dim strSql As String = "select * from XSCReportForm where CLASSNAME='" + Me.ClassName + "'"
            Dim rs As ADODB.Recordset = ct.GetTable(strSql)
            If rs IsNot Nothing Then
                If rs.EOF = False Then
                    报表字体 = CStr(rs.Fields("FontName").Value.ToString)
                    报表记录条数字 = CInt(rs.Fields("GridRowCount").Value.ToString)
                End If
                rs.Close()
                System.Runtime.InteropServices.Marshal.ReleaseComObject(rs)
                rs = Nothing
            End If
        End If
        
    End Sub
End Class
